import FYBaseNode from '../FYBaseNode';
import FYUIMgr from './FYUIMgr';
import { EnumUITween, EnumUIHierarchy } from './UIEnum';

/**
 * 界面基类
 */
export default abstract class FYBaseUI extends FYBaseNode {
    /** 预制的名字 */
    public abstract PrefabName: string;
    /** 层次 */
    public HierarchyType = EnumUIHierarchy.Normal
    /** 设置Widget节点 */
    public Widget: cc.Node = null;
    /** 显示动画 */
    public ShowTweenType: EnumUITween = EnumUITween.None;
    /** 隐藏动画 */
    public HideTweenType: EnumUITween = EnumUITween.None;

    /**
     * 设置节点激活状态
     * @param bActive 是否激活
     */
    public SetActive(bActive) {
        if (this.Widget) {
            this.Widget.active = bActive;
        }
    }

    /** 播放显示缓动动画 */
    public async PlayShowTween(): Promise<void> {
        return new Promise((resolve, reject) => {
            this.Widget.scale = 0;
            this.Widget.stopAllActions();
            cc.tween(this.Widget).to(0.3, { scale: 1 }, { easing: "backOut" }).call(() => { resolve(); }).start()
        })

    }

    /** 播放隐藏缓动动画 */
    public async PlayHideTween(): Promise<void> {
        return new Promise((resolve, reject) => {
            this.Widget.scale = 1;
            this.Widget.stopAllActions();
            cc.tween(this.Widget).to(0.3, { scale: 0 }, { easing: "baseIn" }).call(() => { resolve(); }).start();
        })
    }

    /**
     * 初始化
     * @param param 参数
     */
    public Init(param) {
        this.Widget = cc.find("Widget", this.node);
    }
}
